package com.dupt.system.service.impl;

import java.util.Date;
import java.util.List;

import com.dupt.common.utils.SecurityUtils;
import com.dupt.system.domain.MaterialBorrowReturn;
import com.dupt.system.domain.param.MaterialBorrowReturnParam;
import com.dupt.system.domain.vo.MaterialBorrowReturnVo;
import com.dupt.system.mapper.MaterialBorrowReturnMapper;
import com.dupt.system.service.IMaterialBorrowReturnService;
import com.dupt.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 借用归还信息Service业务层处理
 * 
 * @author zhuanyusun
 * @date 2025-06-09
 */
@Service
public class MaterialBorrowReturnServiceImpl implements IMaterialBorrowReturnService
{
    @Autowired
    private MaterialBorrowReturnMapper materialBorrowReturnMapper;

    /**
     * 查询借用归还信息
     * 
     * @param materialBorrowId 借用归还信息主键
     * @return 借用归还信息
     */
    @Override
    public MaterialBorrowReturn selectMaterialBorrowReturnByMaterialBorrowId(Long materialBorrowId)
    {
        return materialBorrowReturnMapper.selectMaterialBorrowReturnByMaterialBorrowId(materialBorrowId);
    }

    /**
     * 批量查询借用归还信息
     *
     * @param materialBorrowIds 借用归还信息主键
     * @return 借用归还信息
     */
    @Override
    public List<MaterialBorrowReturn> selectMaterialBorrowReturnByMaterialBorrowIds(Long[] materialBorrowIds)
    {
        return materialBorrowReturnMapper.selectMaterialBorrowReturnByMaterialBorrowIds(materialBorrowIds);
    }

    /**
     * 查询借用归还信息列表
     * 
     * @param materialBorrowReturnParam 借用归还信息
     * @return 借用归还信息
     */
    @Override
    public List<MaterialBorrowReturnVo> selectMaterialBorrowReturnList(MaterialBorrowReturnParam materialBorrowReturnParam)
    {
        return materialBorrowReturnMapper.selectMaterialBorrowReturnList(materialBorrowReturnParam);
    }

    /**
     * 新增借用归还信息
     * 
     * @param materialBorrowReturn 借用归还信息
     * @return 结果
     */
    @Override
    public int insertMaterialBorrowReturn(MaterialBorrowReturn materialBorrowReturn)
    {
        //1.保存借用信息
        materialBorrowReturn.setMaterialBorrowId(Long.parseLong(materialBorrowReturn.getBorrowBy().split("-")[1]));
        materialBorrowReturn.setBorrowBy(materialBorrowReturn.getBorrowBy().split("-")[0]);
        materialBorrowReturn.setBorrowTime(DateUtils.getNowDate());
        materialBorrowReturn.setPredictReturnTime(DateUtils.addDays(new Date(),7));
        materialBorrowReturn.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        materialBorrowReturn.setCreateTime(DateUtils.getNowDate());
        return materialBorrowReturnMapper.insertMaterialBorrowReturn(materialBorrowReturn);
    }

    /**
     * 修改借用归还信息
     * 
     * @param materialBorrowReturn 借用归还信息
     * @return 结果
     */
    @Override
    public int updateMaterialBorrowReturn(MaterialBorrowReturn materialBorrowReturn)
    {
        return materialBorrowReturnMapper.updateMaterialBorrowReturn(materialBorrowReturn);
    }

    /**
     * 批量删除借用归还信息
     * 
     * @param materialBorrowIds 需要删除的借用归还信息主键
     * @return 结果
     */
    @Override
    public int deleteMaterialBorrowReturnByMaterialBorrowIds(Long[] materialBorrowIds)
    {
        return materialBorrowReturnMapper.deleteMaterialBorrowReturnByMaterialBorrowIds(materialBorrowIds);
    }

    /**
     * 删除借用归还信息信息
     * 
     * @param materialBorrowId 借用归还信息主键
     * @return 结果
     */
    @Override
    public int deleteMaterialBorrowReturnByMaterialBorrowId(Long materialBorrowId)
    {
        return materialBorrowReturnMapper.deleteMaterialBorrowReturnByMaterialBorrowId(materialBorrowId);
    }
}
